//
//  HttpManager.h
//  jetplayerTestProject
//
//  Created by ott on 14-7-26.
//  Copyright (c) 2014年 ott. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SPRequest.h"

@protocol HttpConectionDelegate;

@protocol HttpManagerDelegate <NSObject>
@optional
- (void) request:(SPRequest *)request didFinish:(NSData *)data;

- (void) request:(SPRequest *)request didFailed:(NSError *)error;

- (void) requestHasBeenCanceld:(SPRequest *)request;

- (void) request:(SPRequest *)request totalBytes:(NSInteger)totalBytes sendBytes:(NSInteger)sendBytes;

@end

@interface HttpManager : NSObject<NSURLConnectionDataDelegate,NSURLConnectionDelegate>

+ (void) sendRequest:(SPRequest *)request;

+ (void) cancelWithRequest:(SPRequest *)request;

+ (void) cancelWithOwner:(id<HttpManagerDelegate>)delegate;

+ (void) cancelAllRequest;

@end


typedef NS_ENUM(NSUInteger, HTTPCharset) {
    HTTPCharsetUTF8,
    HTTPCharsetGBK,
    HTTPCharsetGB2312,
    HTTPCharsetGB18030,
    HTTPCharsetBIG5
};

@interface HttpManager (HTTPRequest)

// ******************** POST METHOD ************************************************************** //
// ******************** POST JSON STRING **************************** //
// the encoding default is NSUTF8StringEncoding.
/// POST json字符串 完成回调block
+ (void) postJson:(NSString *)json toURL:(NSString *)url completion:(CallbackBlock)complete;
+ (void) postJson:(NSString *)json toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;
+ (void) postJson:(NSString *)json toURL:(NSString *)url level:(HTTP_LEVEL)level charset:(HTTPCharset)set completion:(CallbackBlock)complete;
/// POST json字符串 完成回调代理
+ (void) postJson:(NSString *)json toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate;
+ (void) postJson:(NSString *)json toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;
+ (void) postJson:(NSString *)json toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level charset:(HTTPCharset)set;

// ******************** POST STRING **************************** //
+ (void) postString:(NSString *)string toURL:(NSString *)url completion:(CallbackBlock)complete;
+ (void) postString:(NSString *)string toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;
+ (void) postString:(NSString *)string toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete contentType:(HTTPContentType)type;
+ (void) postString:(NSString *)string toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete contentType:(HTTPContentType)type charset:(HTTPCharset)set;
+ (void) postString:(NSString *)string toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate;
+ (void) postString:(NSString *)string toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;
+ (void) postString:(NSString *)string toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level contentType:(HTTPContentType)type;
+ (void) postString:(NSString *)string toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level contentType:(HTTPContentType)type charset:(HTTPCharset)set;

// ******************** POST DATA **************************** //
// the encoding default is NSUTF8StringEncoding.
/// POST NSData 完成回调block
+ (void) postData:(NSData *)data toURL:(NSString *)url completion:(CallbackBlock)complete;
+ (void) postData:(NSData *)data toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;
+ (void) postData:(NSData *)data toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete contentType:(HTTPContentType)type;
+ (void) postData:(NSData *)data toURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete contentType:(HTTPContentType)type charset:(HTTPCharset)set;
+ (void) postData:(NSData *)data toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate;
+ (void) postData:(NSData *)data toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;
+ (void) postData:(NSData *)data toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level contentType:(HTTPContentType)type;
+ (void) postData:(NSData *)data toURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level contentType:(HTTPContentType)type charset:(HTTPCharset)set;

+ (void)postData:(NSData *)body toUrl:(NSString *)url level:(HTTP_LEVEL)level delegate:(id)delegate charset:(HTTPCharset)set ContentType:(HTTPContentType)type completion:(CallbackBlock)complete;


// ******************** GET METHOD ********************************************** //
// the encoding default is NSUTF8StringEncoding.
/// GET 数据 完成回调block
+ (void) getFromURL:(NSString *)url completion:(CallbackBlock)complete;
+ (void) getFromURL:(NSString *)url level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;

+ (void) getFromURL:(NSString *)url paramsString:(NSString *)string completion:(CallbackBlock)complete;
+ (void) getFromURL:(NSString *)url paramsString:(NSString *)string level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;

+ (void) getFromURL:(NSString *)url withParams:(NSDictionary *)params completion:(CallbackBlock)complete;
+ (void) getFromURL:(NSString *)url withParams:(NSDictionary *)params level:(HTTP_LEVEL)level completion:(CallbackBlock)complete;

/// GET 数据 完成回调代理
+ (void) getFromURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate;
+ (void) getFromURL:(NSString *)url delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;

+ (void) getFromURL:(NSString *)url paramsString:(NSString *)string delegate:(id<HttpManagerDelegate>)delegate;
+ (void) getFromURL:(NSString *)url paramsString:(NSString *)string delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;

+ (void) getFromURL:(NSString *)url withParams:(NSDictionary *)params delegate:(id<HttpManagerDelegate>)delegate;
+ (void) getFromURL:(NSString *)url withParams:(NSDictionary *)params delegate:(id<HttpManagerDelegate>)delegate level:(HTTP_LEVEL)level;

+(void)getFromURL:(NSString *)url level:(HTTP_LEVEL)level complete:(CallbackBlock)complete delegate:(id<HttpManagerDelegate>)delegate;
@end